﻿<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8" />
    <title>Door: Door.cs Source File</title>
    <link href="/Content/Help.css" rel="stylesheet" type="text/css" />
    <link href="/Content/css/tabs.css" rel="stylesheet" type="text/css" />
    <link href="/Content/css/doxygen.css" rel="stylesheet" type="text/css" />
</head>
<body>
    <div id="header">
        <img id="logo" alt="StateForge" src="/Content/Images/StateForgeLogo.png" />
        <div id="title">
            <h1>
                C# examples using state machines generated by StateBuilderDotNet
            </h1>
            <h3>
                Door: Door.cs Source File
            </h3>
        </div>
        <div id="menucontainer">
            <ul id="menu">
                <li><a href="/">Home</a></li>
                <li><a href="/Home/Download">Downloads</a></li>
                <li><a href="/Help/state-machine-tools.aspx">Help</a></li>
                <li><a href="/Home/Faq">F.A.Q</a></li>
                <li><a href="/Home/About">Contact us</a></li>
            </ul>
        </div>
    </div>
<!-- Generated by Doxygen 1.7.4 -->
  <div id="navrow1" class="tabs">
    <ul class="tablist">
      <li><a href="index.html"><span>Main&#160;Page</span></a></li>
      <li><a href="namespaces.html"><span>Namespaces</span></a></li>
      <li><a href="annotated.html"><span>Classes</span></a></li>
      <li class="current"><a href="files.html"><span>Files</span></a></li>
    </ul>
  </div>
  <div id="navrow2" class="tabs2">
    <ul class="tablist">
      <li><a href="files.html"><span>File&#160;List</span></a></li>
    </ul>
  </div>
<div class="header">
  <div class="headertitle">
<div class="title">Door.cs</div>  </div>
</div>
<div class="contents">
<a href="_door_8cs.html">Go to the documentation of this file.</a><div class="fragment"><pre class="fragment"><a name="l00001"></a><a class="code" href="namespace_state_forge_1_1_examples_1_1_door.html">00001</a> ﻿namespace StateForge.Examples.Door
<a name="l00002"></a>00002 {
<a name="l00003"></a>00003     <span class="keyword">using</span> System;
<a name="l00004"></a>00004     <span class="keyword">using</span> StateForge.StateMachine;
<a name="l00005"></a>00005     <span class="keyword">using</span> System.Diagnostics;
<a name="l00006"></a>00006     <span class="keyword">using</span> System.Threading;
<a name="l00007"></a>00007 
<a name="l00008"></a><a class="code" href="interface_state_forge_1_1_examples_1_1_door_1_1_i_engine.html">00008</a>     <span class="keyword">public</span> interface <a class="code" href="interface_state_forge_1_1_examples_1_1_door_1_1_i_engine.html">IEngine</a>
<a name="l00009"></a>00009     {
<a name="l00010"></a>00010         <span class="keywordtype">void</span> StartOpen();
<a name="l00011"></a>00011         <span class="keywordtype">void</span> StartClose();
<a name="l00012"></a>00012         <span class="keywordtype">void</span> Stop();
<a name="l00013"></a>00013     }
<a name="l00014"></a>00014 
<a name="l00015"></a><a class="code" href="class_state_forge_1_1_examples_1_1_door_1_1_engine.html">00015</a>     <span class="keyword">public</span> <span class="keyword">class </span><a class="code" href="class_state_forge_1_1_examples_1_1_door_1_1_engine.html">Engine</a> : <a class="code" href="interface_state_forge_1_1_examples_1_1_door_1_1_i_engine.html">IEngine</a>
<a name="l00016"></a>00016     {
<a name="l00017"></a><a class="code" href="class_state_forge_1_1_examples_1_1_door_1_1_engine.html#a8d69696d63a582062985f06ea6223244">00017</a>         <span class="keyword">private</span> <span class="keyword">static</span> TraceSource ts = <span class="keyword">new</span> TraceSource(<span class="stringliteral">&quot;Engine&quot;</span>);
<a name="l00018"></a>00018 
<a name="l00019"></a><a class="code" href="class_state_forge_1_1_examples_1_1_door_1_1_engine.html#a726dacc809bc9710c6abf620d43f6472">00019</a>         <span class="keyword">public</span> <span class="keywordtype">void</span> StartOpen()
<a name="l00020"></a>00020         {
<a name="l00021"></a>00021             ts.TraceInformation(<span class="stringliteral">&quot;StartOpen&quot;</span>);
<a name="l00022"></a>00022         }
<a name="l00023"></a>00023 
<a name="l00024"></a><a class="code" href="class_state_forge_1_1_examples_1_1_door_1_1_engine.html#aabf0ebf816a00c94470eda1196a2535b">00024</a>         <span class="keyword">public</span> <span class="keywordtype">void</span> StartClose()
<a name="l00025"></a>00025         {
<a name="l00026"></a>00026             ts.TraceInformation(<span class="stringliteral">&quot;StartClose&quot;</span>);
<a name="l00027"></a>00027         }
<a name="l00028"></a>00028 
<a name="l00029"></a><a class="code" href="class_state_forge_1_1_examples_1_1_door_1_1_engine.html#afdf4dad0f77ba6fd4cebd88947357505">00029</a>         <span class="keyword">public</span> <span class="keywordtype">void</span> Stop()
<a name="l00030"></a>00030         {
<a name="l00031"></a>00031             ts.TraceInformation(<span class="stringliteral">&quot;Stop&quot;</span>);
<a name="l00032"></a>00032         }
<a name="l00033"></a>00033     }
<a name="l00034"></a>00034 
<a name="l00035"></a><a class="code" href="class_state_forge_1_1_examples_1_1_door_1_1_door.html">00035</a>     <span class="keyword">public</span> <span class="keyword">partial class </span><a class="code" href="class_state_forge_1_1_examples_1_1_door_1_1_door.html">Door</a>
<a name="l00036"></a>00036     {
<a name="l00037"></a><a class="code" href="class_state_forge_1_1_examples_1_1_door_1_1_door.html#a76d3290272d4dd3b9de99eff19efee1a">00037</a>         <span class="keyword">public</span> <a class="code" href="interface_state_forge_1_1_examples_1_1_door_1_1_i_engine.html">IEngine</a> <a class="code" href="class_state_forge_1_1_examples_1_1_door_1_1_door.html#a76d3290272d4dd3b9de99eff19efee1a">Engine</a>;
<a name="l00038"></a>00038     
<a name="l00039"></a><a class="code" href="class_state_forge_1_1_examples_1_1_door_1_1_door.html#a8f4f3768a854bdda9a25565fa01f54c9">00039</a>         <span class="keyword">public</span> DoorContext <a class="code" href="class_state_forge_1_1_examples_1_1_door_1_1_door.html#a8f4f3768a854bdda9a25565fa01f54c9">context</a>;
<a name="l00040"></a><a class="code" href="class_state_forge_1_1_examples_1_1_door_1_1_door.html#a24d411751e88c5c040dbe8e8871b08b8">00040</a>         <span class="keyword">private</span> <span class="keyword">static</span> readonly <span class="keywordtype">string</span> traceName = <span class="stringliteral">&quot;Door&quot;</span>;
<a name="l00041"></a><a class="code" href="class_state_forge_1_1_examples_1_1_door_1_1_door.html#a4f2f10ac2ce1457df395fd9411326eed">00041</a>         <span class="keyword">private</span> <span class="keyword">static</span> TraceSource ts = <span class="keyword">new</span> TraceSource(traceName);
<a name="l00042"></a><a class="code" href="class_state_forge_1_1_examples_1_1_door_1_1_door.html#a1f63da8ffc39975ec290adf9f25f422e">00042</a>         <span class="keyword">private</span> <span class="keyword">static</span> AutoResetEvent autoResetEvent = <span class="keyword">new</span> AutoResetEvent(<span class="keyword">false</span>);
<a name="l00043"></a>00043 
<a name="l00044"></a><a class="code" href="class_state_forge_1_1_examples_1_1_door_1_1_door.html#a1d1db69204a3e15f8d5641c9b4355a14">00044</a>         <span class="keyword">public</span> <a class="code" href="class_state_forge_1_1_examples_1_1_door_1_1_door.html">Door</a>()
<a name="l00045"></a>00045         {
<a name="l00046"></a>00046             this.<a class="code" href="class_state_forge_1_1_examples_1_1_door_1_1_engine.html">Engine</a> = <span class="keyword">new</span> <a class="code" href="class_state_forge_1_1_examples_1_1_door_1_1_engine.html">Engine</a>();
<a name="l00047"></a>00047             InitializeContext();
<a name="l00048"></a>00048         }
<a name="l00049"></a>00049 
<a name="l00050"></a><a class="code" href="class_state_forge_1_1_examples_1_1_door_1_1_door.html#a7dc299d9d93cfc77011d8be94911431e">00050</a>         <span class="keyword">public</span> <a class="code" href="class_state_forge_1_1_examples_1_1_door_1_1_door.html">Door</a>(<a class="code" href="interface_state_forge_1_1_examples_1_1_door_1_1_i_engine.html">IEngine</a> engine)
<a name="l00051"></a>00051         {
<a name="l00052"></a>00052             this.<a class="code" href="class_state_forge_1_1_examples_1_1_door_1_1_engine.html">Engine</a> = engine;
<a name="l00053"></a>00053             InitializeContext();
<a name="l00054"></a>00054         }
<a name="l00055"></a>00055 
<a name="l00056"></a><a class="code" href="class_state_forge_1_1_examples_1_1_door_1_1_door.html#a0931a283fe2db04ca65921ad46f5e42d">00056</a>         <span class="keyword">private</span> <span class="keywordtype">void</span> InitializeContext()
<a name="l00057"></a>00057         {
<a name="l00058"></a>00058             this.context = <span class="keyword">new</span> DoorContext(<a class="code" href="class_state_forge_1_1_examples_1_1_door_1_1_engine.html">Engine</a>);
<a name="l00059"></a>00059             this.context.Observer = ObserverTrace.Instance(traceName);
<a name="l00060"></a>00060             this.context.EndHandler += <span class="keyword">new</span> EventHandler&lt;EventArgs&gt;(StateMachineEnd);
<a name="l00061"></a>00061             this.context.EnterInitialState();
<a name="l00062"></a>00062         }
<a name="l00063"></a>00063 
<a name="l00064"></a><a class="code" href="class_state_forge_1_1_examples_1_1_door_1_1_door.html#ac838c3ea454fabe9b5b58fbd494d5892">00064</a>         <span class="keyword">private</span> <span class="keywordtype">void</span> StateMachineEnd(<span class="keywordtype">object</span> sender, EventArgs e)
<a name="l00065"></a>00065         {
<a name="l00066"></a>00066             ts.TraceInformation(<span class="stringliteral">&quot;State machine has ended&quot;</span>);
<a name="l00067"></a>00067             autoResetEvent.Set();
<a name="l00068"></a>00068         }
<a name="l00069"></a>00069 
<a name="l00070"></a><a class="code" href="class_state_forge_1_1_examples_1_1_door_1_1_door.html#ae0622c55ef8fa938c7d366e720a49a81">00070</a>         <span class="keyword">public</span> <span class="keywordtype">void</span> Test01()
<a name="l00071"></a>00071         {
<a name="l00072"></a>00072             this.Start();
<a name="l00073"></a>00073             this.OpenRequest();
<a name="l00074"></a>00074             this.Quit();
<a name="l00075"></a>00075             autoResetEvent.WaitOne();
<a name="l00076"></a>00076         }
<a name="l00077"></a>00077 
<a name="l00078"></a><a class="code" href="class_state_forge_1_1_examples_1_1_door_1_1_door.html#a8bcedc32e4db10d3ef2f7550d1822917">00078</a>         <span class="keyword">static</span> <span class="keywordtype">void</span> Main(<span class="keywordtype">string</span>[] args)
<a name="l00079"></a>00079         {
<a name="l00080"></a>00080             var door = <span class="keyword">new</span> <a class="code" href="class_state_forge_1_1_examples_1_1_door_1_1_door.html">Door</a>();
<a name="l00081"></a>00081             door.Test01();
<a name="l00082"></a>00082             ts.TraceInformation(<span class="stringliteral">&quot;Door has ended&quot;</span>);
<a name="l00083"></a>00083             Environment.Exit(0);
<a name="l00084"></a>00084         }
<a name="l00085"></a>00085     }
<a name="l00086"></a>00086 }
</pre></div></div>
</div>
﻿<div id="footer">
    <hr />
    <p>
        Copyright &copy; 2011 StateForge.</p>
    <hr />
</div>
</body> </html> 
